package com.jyxd.web.data.basic;

import cn.hutool.crypto.digest.MD5;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.util.Date;

@Data
@TableName("table_nursing_task")
public class NursingTask {

    /**
     * 序列
     */
    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    @Id
    @Column(name = "id", length = 32, nullable = false)
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid.hex")
    private String id;

    /**
     * 病人主键id
     */
    @Column(name = "patient_id")
    private String patientId;
    @Column(name = "nursing_categories")
    private String nursingCategories;
    @Column(name = "nursing_type")
    private String nursingType;
    @Column(name = "start_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    private Date startTime;
    @Column(name = "end_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date endTime;
    @Column(name = "discard_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date discardTime;
    @Column(name = "discard_reason")
    private String discardReason;
    @Column(name = "status")
    private int status;
    @Column(name = "cron_exp")
    private String cronExp;
    @Column(name = "frequency_id")
    private String frequencyId;

    @Transient
    @TableField(exist = false)
    private Long frequencyDuration;

    @Transient
    @TableField(exist = false)
    private String frequencyDesc;

    @TableField(exist = false)
    @Transient
    private int dataChangeStatus = 0;
    @Transient
    @TableField(exist = false)
    private Date nextExecuteTime;

    public String uniqueId() {
        String key = this.patientId + "_" +
                this.nursingCategories + "_" +
                this.nursingType;
        return MD5.create().digestHex(key);
    }

    public void setNextExecuteTime(Date nextExecuteTime) {
        this.nextExecuteTime = nextExecuteTime;
    }

    public Date getNextExecuteTime() {
        return nextExecuteTime;
    }
}
